package com.wl.dzt.basic.shir;

import com.wl.dzt.basic.constant.SmsTemplateConstant;
import com.wl.dzt.basic.entity.BasicOrganization;
import com.wl.dzt.basic.service.BasicOrganizationService;
import com.wl.dzt.basic.service.callback.SmsSendSwitchCallback;
import com.wl.dzt.sys.controller.annotation.Shir;
import com.wl.dzt.sys.controller.param.shir.ShirHandler;
import com.wl.dzt.sys.controller.param.shir.ShirTypes;
import com.wl.dzt.sys.util.AliyunSmsUtils;
import com.wl.dzt.sys.util.DynaBean;
import com.wl.dzt.sys.util.YPSmsUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author wl_code@163.com
 * @version 1.0
 * @date 2018/7/10/010
 * @description 组织机构
 */
@Component
public class BasicOrganizationShir {
    @Resource
    private BasicOrganizationService basicOrganizationService;

    /**
     * <b>创建企业域</b>

     *
     * @param handler
     * @return
     */
    @Shir(ShirTypes.MIDDLE)
    public String createArea(ShirHandler handler) {
        BasicOrganization organization = (BasicOrganization) handler.getParam().getEntity();
        organization.setCreateDate(new Date());
        String url = handler.invoke();
        if (handler.getParam().isSuccess()
                && basicOrganizationService.createArea(organization, (area, user, pwd) -> SmsSendSwitchCallback.handler(organization.getId(), () -> AliyunSmsUtils.send(user.getPhone(), "SMS_139237553", new DynaBean().set("organName", organization.getOrganName()).set("uname", user.getUname()).set("pwd", pwd))))) {
        }
        return url;
    }
}